package Task28;

import java.awt.EventQueue;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JList;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class ShowWindow {
	private JFrame frmShowWindow;
	private JList list;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ShowWindow window = new ShowWindow();
					window.frmShowWindow.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public ShowWindow() {
		initialize();
	}

	private void initialize() {
		frmShowWindow = new JFrame();
		frmShowWindow.setTitle("Show window");
		frmShowWindow.setBounds(100, 100, 450, 300);

		JButton btnClose = new JButton("Close");
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frmShowWindow.setVisible(false);
			}
		});

		JScrollPane scrollPane = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(
				frmShowWindow.getContentPane());
		groupLayout.setHorizontalGroup(groupLayout
				.createParallelGroup(Alignment.LEADING)
				.addComponent(btnClose, GroupLayout.DEFAULT_SIZE, 442,
						Short.MAX_VALUE)
				.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 442,
						Short.MAX_VALUE));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(
				Alignment.LEADING).addGroup(
				Alignment.TRAILING,
				groupLayout
						.createSequentialGroup()
						.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE,
								238, Short.MAX_VALUE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(btnClose)));

		list = new JList();
		scrollPane.setViewportView(list);
		frmShowWindow.getContentPane().setLayout(groupLayout);
	}

	public void showWindow() {
		frmShowWindow.setVisible(true);
	}

	public void hideWindow() {
		frmShowWindow.setVisible(false);
	}

	public void setText(ArrayList<String> text) {
		DefaultListModel myModel = new DefaultListModel();

		for (int i = 0; i < text.size(); i++) {
			myModel.addElement(text.get(i));
			list.setModel(myModel);
		}
	}



}
